package logic

import (
	"context"
	"sport/models/mysql"
	"sport/sportrpc/internal/svc"
	"sport/sportrpc/sportrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LikedLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLikedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikedLogic {
	return &LikedLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 帖子点赞
func (l *LikedLogic) Liked(in *sportrpc.LikedRequest) (*sportrpc.LikedResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.Post
	user.Liked = user.Liked + 1
	mysql.DB.Where("id = ?", in.Id).Find(&user)
	return &sportrpc.LikedResponse{
		UserId:  int64(user.UserId),
		ForumId: int64(user.ForumId),
		Title:   user.Title,
		Content: user.Content,
		Liked:   int64(user.Liked),
	}, nil
}
